package com.wlt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlt.pojo.Permission;
import com.wlt.result.BaseResult;
import com.wlt.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台权限
 */
@RestController
@RequestMapping("/permission")
public class PermissionController
{
    @DubboReference
    private PermissionService permissionService;
    
    /**
     * 新增权限
     * @param permission    权限对象
     * @return              执行结果
     */
    @PostMapping ("/add")
    public BaseResult add (@RequestBody Permission permission)
    {
        permissionService.add(permission);
        
        return BaseResult.success();
    }
    
    /**
     * 修改权限
     * @param permission    权限对象
     * @return              执行结果
     */
    @PutMapping("/update")
    public BaseResult update (@RequestBody Permission permission)
    {
        permissionService.update(permission);
        
        return BaseResult.success();
    }
    
    /**
     * 删除权限
     * @param pid   权限id
     * @return      执行结果
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Long pid)
    {
        permissionService.delete(pid);
        
        return BaseResult.success();
    }
    
    /**
     * 查询权限
     * @param pid   权限id
     * @return      查询结果
     */
    @GetMapping ("/findById")
    public BaseResult findById (Long pid)
    {
        return BaseResult.success(permissionService.findById(pid));
    }
    
    /**
     * 分页查询权限
     * @param page  页数
     * @param size  每页条数
     * @return      查询结果
     */
    @GetMapping ("/search")
    public BaseResult<Page<Permission>> search (int page, int size)
    {
        return BaseResult.success(permissionService.search(page, size));
    }
    
    /**
     * 查询所有权限
     * @return  查询结果
     */
    @GetMapping ("/findAll")
    public BaseResult<List<Permission>> findAll ()
    {
        return BaseResult.success(permissionService.findAll());
    }
}
